﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Linq.Expressions;

namespace aQuery
{
    public static class ActionReaderQuery
    {
        
        public static ActionReader<T> Do<T>(this ActionReader<T> target, ActionAtTarget<T> act) where T : class
        {
            target.Actions.Add(act);
            return target;
        }

        public static ActionReader<T> Do<T>(this T target, ActionAtTarget<T> act) where T : class
        {
            return new ActionReader<T>(target).Do(act);
        }

        public static PropositionReader<T> While<T>(this ActionReader<T> target, ConditionAtTarget<T> condition) where T : class
        {
            return new PropositionReader<T>(target, ConditionUsage.While, condition);
        }

        public static PropositionReader<T> If<T>(this ActionReader<T> target, ConditionAtTarget<T> condition) where T : class
        {
            return new PropositionReader<T>(target, ConditionUsage.If, condition);
        }

        public static ActionObserver<T> When<T>(this ActionReader<T> target, Expression<PropertyOfTarget<T>> property) 
            where T : class, INotifyPropertyChanged
        {
            return new ActionObserver<T>(target, property);
        }

        public static PropositionReader<T> And<T>(this PropositionReader<T> target, ConditionAtTarget<T> condition) where T : class
        {
            target.Conditions.Add(condition);
            return target;
        }

        public static ActionRepeater<T> Times<T>(this ActionReader<T> target, int numberOfTimes) where T : class
        {
            return new ActionRepeater<T>(target, numberOfTimes);
        }

        public static void Execute(this IExecutable target)
        {
            target.ExecuteYourself();
        }
        
    }
}
